﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Templates.SharpParts.Logic.Model.Enum;

namespace Templates.SharpParts.Shells
{
	public partial class ClassShell 
	{
		[DataMember()]
		public string NamespaceName { get; set; }
		[DataMember()]
		public string ClassName { get; set; }

		public Inheritance BaseClassName{ get; set; }
		public IEnumerable<Inheritance> Interfaces{ get; set; }

		public override void BeforeToString()
		{
			StringBuilder result = new StringBuilder();

			bool baseClassExist = BaseClassName != null && !string.IsNullOrWhiteSpace(BaseClassName.Name);

			var interfacesList = Interfaces != null ? Interfaces.Select(x => x).ToList() : new List<Inheritance>();

			if (baseClassExist || interfacesList.Count > 0)
			{
				result.Append(": ");
				if (baseClassExist)
				{
					result.Append(BaseClassName.Name);
					AdditionalNamespace = BaseClassName.Namespace;
					//AddNamespace(BaseClassName.Namespace);
				}

				if (interfacesList.Count > 0)
				{
					if (baseClassExist)
						result.Append(", ");
					for (int i = 0; i < interfacesList.Count; i++)
					{
						result.Append(interfacesList[i].Name);
						AdditionalNamespace = interfacesList[i].Namespace;

						//AddNamespace(interfacesList[i].Namespace);

						if (i + 1 < interfacesList.Count)
							result.Append(", ");
					}
				}
			}

			Inheritment = result.ToString();
		}

		[DataMember()]
		private string Inheritment { get; set; }

		[DataMember()]
		public CsAccessor Accessor { get; set; }

	}
}
